package model

type ModifiedFileInfo struct {
	Old *FileInfo
	New *FileInfo
}

func BuildModifiedFileInfos(fileInfos []*FileInfo) []*ModifiedFileInfo {
	modifiedFileInfos := make([]*ModifiedFileInfo, 0, len(fileInfos))
	for _, fileInfo := range fileInfos {
		modifiedFileInfos = append(modifiedFileInfos, &ModifiedFileInfo{
			Old: fileInfo,
			New: fileInfo.Clone(),
		})
	}
	return modifiedFileInfos
}

func NewModifiedFileInfo(fileInfo *FileInfo) *ModifiedFileInfo {
	return &ModifiedFileInfo{
		Old: fileInfo,
		New: fileInfo.Clone(),
	}
}

func BatchGetDirs(fileInfos []*ModifiedFileInfo) []string {
	dirSet := make(map[string]struct{})
	for _, fileInfo := range fileInfos {
		dirSet[fileInfo.Old.Dir] = struct{}{}
	}

	dirs := make([]string, 0, len(dirSet))
	for dir := range dirSet {
		dirs = append(dirs, dir)
	}

	return dirs
}
